﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMO.Models;

namespace SMO.Models.SimplObject
{
    public class StockRepository
    {
        private SMO_LinQDataContext datacontent = new SMO_LinQDataContext();
        public IQueryable<Stock> GetAll()
        {
            return datacontent.Stocks;
        }

        public Stock GetByStockID(string id)
        {
            return datacontent.Stocks.SingleOrDefault(s => s.StockId.ToString().Trim() == id.Trim());
        }

        public Stock GetFirst()
        {
            return datacontent.Stocks.FirstOrDefault();
        }

        public void Add(Stock stock)
        {
            datacontent.Stocks.InsertOnSubmit(stock);
        }

        public void Delete(Stock stock)
        {
            datacontent.Stocks.DeleteOnSubmit(stock);
        }

        public void Save()
        {
            datacontent.SubmitChanges();
        } 
    }
}
